package com.gs.api.projects.bzapplets.web;

import com.gs.api.projects.bzapplets.entity.BzClassification;
import com.gs.api.projects.bzapplets.entity.BzConfig;
import com.gs.api.projects.bzapplets.service.BzClassificationService;
import com.gs.api.projects.bzapplets.service.BzConfigService;
import com.gs.api.config.Constant;
import com.gs.api.core.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author guoyunfei on 2021/7/9 14:03
 * @className BzClassificationDao
 * @description TODO
 * @Version 1.0
 */
@Api(tags = "壁纸分类")
@RestController
@RequestMapping("{appid}/classification")
public class BzClassificationController {

    @Autowired
    private BzClassificationService bzClassificationService;

    @Autowired
    private BzConfigService bzConfigService;


    @ApiOperation(value = "壁纸分类列表", notes="壁纸分类列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "appid", value = "小程序appid", required = true, dataType = "String"),
    })
    @GetMapping("list")
    public Result bzClassificationList (@PathVariable String appid){

        List<BzConfig> configList = bzConfigService.getConfig(Constant.API_OSS_TYPE);
        String value = configList.get(0).getValue();
        BzClassification bzClassification = new BzClassification();
        bzClassification.setEnable(1);
        //多账号时开放
        bzClassification.setAppid(appid);
        List<BzClassification> bzClassifications = bzClassificationService.selectList(bzClassification);
        for (int i = 0; i < bzClassifications.size(); i++) {
            String link = bzClassifications.get(i).getLink();
            bzClassifications.get(i).setLink(value + link);
        }
        return Result.success(bzClassifications);
    }

}
